<template name="putawayMoveDocRFItemInputPage">
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true" backRouterName="putawayMoveDocByItemRFListPage">
			<block slot="content">按货品上架</block>
		</cu-custom>
		<form>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.1s'}]">
				<view class="title">ASN：</view>{{this.myFormData.asnCode}}
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.2s'}]">
				<view class="title">货品名称：</view>{{this.myFormData.itemName}}
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.3s'}]">
				<view class="title">货品编码：</view>{{this.myFormData.itemCode}}
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.4s'}]">
				<view class="title">计划上架数量：</view>{{this.myFormData.allocateQty}}
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.5s'}]">
				<view class="title">包装/件装量：</view>{{this.myFormData.packageInfo}}
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.6s'}]">
				<view class="title">库存状态：</view>{{this.myFormData.invStatus}}
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.7s'}]">
				<view class="title">推荐上架库位：</view>{{this.myFormData.toLocationCode}}
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.8s'}]">
				<view class="title">库位：</view>
				<input placeholder="请输入库位" name="input" v-model="myFormData.locationCode" @confirm="onSubmit"></input>
				<text class="cuIcon-scan" @click="InputFocus"></text>
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.9s'}]">
				<view class="title">上架数量：</view>
				<input placeholder="请输入上架数量" name="input" v-model="myFormData.putQty"></input>
			</view>
			<view class="padding flex flex-direction">
				<button class="cu-btn bg-blue lg"  @click="onSubmit">上架确认</button>
			</view>
		</form>
	</view>
</template>

<script>
	import crypto from '@/api/crypto.js' 
	export default {
		data() {
			return {
				myFormData:{
					taskId:'',
					asnCode:'',
					itemName:'',
					itemCode:'',
					allocateQty:0,
					packageInfo:'',
					invStatus:'',
					toLocationCode:'',
					locationCode:'',
					putQty:0,
					workerId:'',
				},
				pageTaskId:'',
				putAwayConfirmByItemInitUrl:'/pda/initPutAwayConfirmByItem',
				putAwayConfirmByItemUrl:'/pda/putAwayConfirmByItem',
			};
		},
		onLoad: function (option) {
			if(!option.item){
				uni.navigateTo({
					url: '/pages/wms/putawayMoveDocByItemRFListPage'
				});
				return;
			}
			const tempItem = JSON.parse(decodeURIComponent(option.item));
			this.pageTaskId = tempItem.taskId;
			//重新加载数据
			this.$http.get(this.putAwayConfirmByItemInitUrl,{params:{taskId:crypto.encrypt(this.pageTaskId)}}).then(res=>{
			  if(res.data.success){
				  this.myFormData = res.data.result;
			  }else{
				 this.$tip.error(res.data.message);
			  }
			}).catch(()=>{
				this.$tip.loaded();
			});
		},
		methods: {
			onSubmit() {
				this.myFormData.workerId = this.$store.getters.userid;
				if(!this.myFormData.locationCode){
					this.$tip.error('请扫描收货库位!');
					return;
				}
				this.$http.post(this.putAwayConfirmByItemUrl,this.myFormData).then(res=>{
					let statusCode = res.data.code;
					if (res.data.success){
						if(statusCode == 1){
							this.myFormData.locationCode=''
							this.myFormData.putQty=''
							uni.navigateTo({
								url: '/pages/wms/putawayMoveDocRFItemInputPage?item='+ encodeURIComponent(JSON.stringify(this.myFormData))
							});
						}else{
							uni.navigateTo({
								url: '/pages/wms/putawayMoveDocByItemRFListPage?item='+ encodeURIComponent(JSON.stringify(this.myFormData))
							});
						}
					}else{
						this.$tip.error(res.data.message);
					}
				}).catch(()=>{
					this.$tip.loaded();
				});
			},
			InputFocus() {
				 let that = this;
				 // 调起条码扫描
				 uni.scanCode({
					 onlyFromCamera: true,
					 success: function (res) {
						 that.myFormData.palletNo = res.result
					 }
				 });
			},
		}
	}
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
</style>